package com.ruoyi.common.mytools;

import java.util.Random;
import java.util.UUID;

public class Tools {
    static Random randObj = new Random();
    // 生成6位随机验证码
    public static String generateCode6() {
        return Integer.toString(100000 + randObj.nextInt(900000));
    }
    // 生成5位随机验证码
    public static String generateCode5() {
        return Integer.toString(10000 + randObj.nextInt(90000));
    }
    // 生成4位随机验证码
    public static String generateCode4() {
        return Integer.toString(1000 + randObj.nextInt(9000));
    }
    // 生成2位随机验证码
    public static String generateCode2() {
        return Integer.toString(10 + randObj.nextInt(50));
    }
    //生成uuid
    public static String generateUUID(){
            UUID randomUUID = UUID.randomUUID();
            return randomUUID.toString().replaceAll("-", "");
    }
    //生成随机字符串
    public static String generateRandomStr(int length){
        String alphabetsInUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String alphabetsInLowerCase = "abcdefghijklmnopqrstuvwxyz";
        String numbers = "0123456789";
        // create a super set of all characters
        String allCharacters = alphabetsInLowerCase + alphabetsInUpperCase + numbers;
        // initialize a string to hold result
        StringBuffer randomString = new StringBuffer();
        // loop for 10 times
        for (int i = 0; i < length; i++) {
            // generate a random number between 0 and length of all characters
            int randomIndex = randObj.nextInt(allCharacters.length());
            // retrieve character at index and add it to result
            randomString.append(allCharacters.charAt(randomIndex));
        }
        return randomString.toString();
    }
    //生成#A+26字母随机字符
    public static String generateRandomAand26(int length){
        String alphabetsInUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        // create a super set of all characters
        String allCharacters =alphabetsInUpperCase;
        // initialize a string to hold result
        StringBuffer randomString = new StringBuffer();
        // loop for 10 times
        for (int i = 0; i < length; i++) {
            // generate a random number between 0 and length of all characters
            int randomIndex = randObj.nextInt(allCharacters.length());
            // retrieve character at index and add it to result
            randomString.append("#Z"+allCharacters.charAt(randomIndex));
        }
        return randomString.toString();
    }
}
